package net.slteam.base;

import net.slteam.base.util.SpringUtil;

import javax.persistence.Transient;

/**
 * ClassName: ITranslatorUserName
 * Description:
 * date: 2023/10/28 9:25 AM
 *
 * @author calm
 * @since JDK 1.8
 */
public interface ITranslatorUserName {

    default String getCreator() {return null;};

    default String getUpdater() {return null;}

    @Transient
    default  String getCreatorName() {
        IUserService userService = SpringUtil.getBean(IUserService.class);
        if (userService != null) {
            if (getCreator() != null && getCreator() != "") {
                if (isDigit(getCreator()) )
                    return userService.getUserName(Long.valueOf(getCreator()));
                else
                    return getCreator();
            }
        }
        return getCreator();
    }
    
    @Transient
    default String getUpdaterName() {
        IUserService userService = SpringUtil.getBean(IUserService.class);
        if (userService != null) {
            if (getUpdater() != null && getUpdater() != "") {
                if (isDigit(getUpdater()) )
                    return userService.getUserName(Long.valueOf(getUpdater()));
                else
                    return getUpdater();
            }
        }
        return getUpdater();
    }
    
    static boolean isDigit(String str){
        if(str == null || str.trim().equals("")){
            return false;
        }
        return str.matches("^\\d+$");
    }
    
}
